package com.copyctrl.admin.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.copyctrl.admin.dto.DynamicDTO;
import com.copyctrl.admin.service.DynamicService;
import com.copyctrl.mapper.CampDynamicMapper;
import com.copyctrl.mapper.CampUserMapper;
import com.copyctrl.model.CampDynamic;
import com.copyctrl.model.CampDynamicExample;
import com.copyctrl.model.CampUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author:JH
 * @version:1.0
 */
@Service
public class DynamicServiceImpl implements DynamicService {
    @Autowired
    CampDynamicMapper mapper;
    @Autowired
    CampUserMapper userMapper;
    @Override
    public List<DynamicDTO> findAll() {
        CampDynamicExample example = new CampDynamicExample();
        example.createCriteria().andIdIsNotNull();
        return mapper.selectByExampleWithBLOBs(example).stream().map(dynamic->{
            CampUser user = userMapper.selectByPrimaryKey(dynamic.getUserId());
            DynamicDTO dynamicDTO = BeanUtil.copyProperties(dynamic, DynamicDTO.class);
            dynamicDTO.setUser(user);
            return dynamicDTO;
        }).collect(Collectors.toList());

    }
}
